(function () {
  new Swiper('.swiper-container', {
    autoplay: {
      delay: 3000,
      disableOnInteraction: false,
    },
    loop: true,
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
    },
  });

  new Swiper('.swiper-goods-container', {
    autoplay: {
      delay: 3000,
      disableOnInteraction: false,
    },
    loop: true,
    navigation: {
      nextEl: '.swiper-button-next',
      prevEl: '.swiper-button-prev',
    },
    pagination: {
      el: '.swiper-pagination',
      clickable: true,
      bulletClass: 'swiper-pagination-bullet middle-swiper-icon',
      bulletActiveClass: 'middle-swiper-icon-active',
      renderBullet: function (index, className) {
        let src = "";

        switch (index) {
          case 0: src = './images/index_middle_banner_1.png'; break;
          case 1: src = './images/index_middle_banner_2.png'; break;
          case 2: src = './images/index_middle_banner_3.png'; break;
          case 3: src = './images/index_middle_banner_4.png'; break;
          case 4: src = './images/index_middle_banner_5.png'; break;
        }

        return '<img class="' + className + '" src="' + src + '" role="button" aria-label="Go to slide ' + (index + 1) + '">';
      },
    },
  });
})()

window.addEventListener('load', function () {
  let tapTop = document.querySelector('.fixed-top')
  let banner = document.querySelector('.banner').offsetHeight

  pageScroll(tapTop, banner)
  window.addEventListener('scroll', function () {
    pageScroll(tapTop, banner)
  })

  tapTop.addEventListener('click', function () {
    animationTapTop(window, 0);
  })

  videoPlay()


})

function videoPlay() {
  let videomask = document.querySelector('.video-mask')
  let videobtn = document.querySelector('.video_btn')
  let video = document.querySelector('video')

  videobtn.addEventListener('click', function () {
    video.paused ? video.play() : video.pause();
  })

  video.addEventListener('play', function () {
    videomask.style.display = "none"
    video.controls = true
  })

  video.addEventListener('pause', function () {
    videomask.style.display = "block"
  })
}

function pageScroll(tapTop, domOffset) {
  window.pageYOffset >= domOffset
    ? tapTop.style.display = 'block'
    : tapTop.style.display = 'none';
}

//返回顶部的动画函数
function animationTapTop(obj, target, callback) {
  clearInterval(obj.timer)
  obj.timer = setInterval(function () {
    if (window.pageYOffset == target) {
      clearInterval(obj.timer)
      callback && callback();
    } else {
      var step = (target - window.pageYOffset) / 10
      step = step > 0 ? Math.ceil(step) : Math.floor(step)
      window.scroll(target, window.pageYOffset + step)
    }
  }, 15)
}